<template>
  <div class="CommentCountPage">
    <div class="NotCommentCount" v-if="CommentList.total == '0'">没有评论</div>
    <div v-else>
      <div
        class="CommentUser-box"
        v-for="item in CommentList.data"
        :key="item.id"
      >
        <!-- 头部 -->
        <div class="CommentUser-box-top">
          <div>
            <img :src="item.user.avatar_url" alt="没头像" />
            <div class="CommentUser-box-top-text">
              <p>{{ item.user.nickname }}</p>
              <p>{{ item.created_time }}</p>
            </div>
          </div>
          <div class="CommentUser-box-topGood">
            <van-icon
              v-show="item.id != LikeShow"
              @click="GetLikeShow(item.id)"
              name="good-job-o"
            />
            <van-icon
              v-show="item.id == LikeShow"
              name="good-job"
              @click="GetLikeShow('')"
            />
            <span>{{ item.supports_count }}</span>
          </div>
        </div>
        <!-- 评论内容 -->
        <div class="CommentUser-box-mid">
          {{ item.outer_text }}
        </div>
        <!-- 属于哪个文章 -->
        <div class="CommentUser-box-bot">{{ item.inner_text }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { CommentCountPage } from "@/api/request";
export default {
  name: "CommentCountPage",
  props: ["ItemContent"],
  data() {
    return {
      // 页面id
      contentId: 0,
      // 评论页数
      PageIndex: 1,
      // 请求到的评论数据
      CommentList: [],

      // 点赞
      LikeShow: "",
    };
  },
  activated() {
    this.$nextTick(() => {});
  },
  mounted() {
    this.$nextTick(() => {
      // 赋值页面id
      this.contentId = this.ItemContent.content_id;
      CommentCountPage({
        content_id: this.contentId,
        sort: "new",
        page: this.PageIndex,
      }).then(({ data }) => {
        this.CommentList = data.data;
        // console.log(this.CommentList);
      });
    });
  },
  methods: {
    GetLikeShow(id) {
      console.log(id);
      this.LikeShow = id;
    },
  },

};
</script>

<style lang="scss" scoped>
.CommentCountPage {
  padding: 0 1.25rem;
  margin-bottom: 2.5rem;
  .NotCommentCount {
    text-align: center;
    margin: 1.25rem 0;
  }
  .CommentUser-box {
    border-bottom: 1px solid #eee;
    margin: 0.625rem 0;
    .CommentUser-box-top {
      display: flex;
      justify-content: space-between;
      > div {
        display: flex;
        img {
          width: 2.5rem;
          height: 2.5rem;
          border-radius: 50%;
        }
        .CommentUser-box-top-text {
          margin-left: 0.625rem;
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          p {
            font-size: 0.8125rem;
          }
          p:nth-child(1) {
          }
          p:nth-child(2) {
            font-size: 0.75rem;
            color: var(--fontcolor);
          }
        }
      }
      .CommentUser-box-topGood {
        display: flex;
        align-items: center;
        span {
          font-size: 0.625rem;
        }
      }
    }
    .CommentUser-box-mid {
      font-size: 0.8125rem;
      margin: 0.625rem 0;
      line-height: 1.25rem;
    }
    .CommentUser-box-bot {
      font-size: 0.75rem;
      background-color: #f3f4f6;
      padding: 0.625rem;
      margin-bottom: 1rem;
    }
  }
}
</style>